#课外发现：
#输出字符串的字母数或列表的元素的个数
print(len('test'))

#生成随机数
import random
print(random.randint(0,9))#生成0到9之间的随机数

#添加负号
a = 10
print(-a)

# 查看运行时间
import time
Start = time.time()
  # 中间代码模块
End = time.time()
print((End-Start))

# max()函数的用法
list_test0 = [123,456,122]
print(max(list_test0))
  # 或者……
print(max(123,456,122))

# 输出商和余数的函数（divmod）
num1 = 10
num1, num2 = divmod(num1, 100)
print(num1, num2)

# 输出到文件
f = open('质数py.txt', 'a')# 这个文件专门用来存储我刷到的质数的
e = int(input('请输入一个数'))

DangQianJinDu = 2300000
for lnum in range(DangQianJinDu, e + 1):
    m = 0
    genhao_lnum = lnum ** (1 / 2)
    for num in range(2, lnum):
        if lnum % num == 0:
            m = lnum
            break
        if num > genhao_lnum:
            break
    if m == 0:
        f.write(str(lnum) + ',')

f.close()

# zip的应用
l1 = [1, 2, 3]

l2 = ['a', 'b', 'c']

print(list(zip(l1, l2)))

# 异常处理
try:
    test = '1' + 1
except TypeError:
    print('Error')
else:
    print('成功')
finally:
    pass

# lambda的使用
he = lambda x, y: x + y
print(he(1, 2))

# 转16进制
print(hex(255))

# python画布
# import _tkinter

# 生成器
def scq():
    print(1)
    yield
    print(2)
    yield
    print(3)
    yield

scq()
scq()
scq()

import ctypes

# 字节码
import dis

def s():
    return 1 + 1
dis.dis(s)

with open("质数py.txt", "w") as f:
    f.write("blabla")

# 装饰器
def times(f):
    def tick():
        start = time.time()
        f()
        t = time.time() - start
        print(t)
        return t
    return tick

@times
def test():
    time.sleep(1)

a = test()
print(a)

# filter
l = [1,2,3,4,5]
l = filter(lambda x: x % 2 == 0, l)
print(l)

# 静态方法与静态变量

class test:
    count = 0
    def __init__(self):
        test.plus()

    @classmethod # @staticmethod也一样
    def plus(cls):
        test.count += 1


test()
print(test.count)
test()
print(test.count)
